package com.example.gbasedemo.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.gbasedemo.mapper.FinanceLoanMapper;
import com.example.gbasedemo.mapper.FinanceLoanPojo;
import com.example.gbasedemo.mapper.TradeBaseDetailMapper;
import com.example.gbasedemo.mapper.TradeBaseDetailPojo;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.sql.Date;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

@Service
public class ServiceFinanceLoan extends ServiceImpl<FinanceLoanMapper, FinanceLoanPojo> {

    public void createTable() {
        baseMapper.createTable();
    }

    public void insert() {
        FinanceLoanPojo pojo = getPojo(1);
        baseMapper.insert(pojo);
    }

    public void updateRow() {
        FinanceLoanPojo pojo = getPojo(1);
        pojo.setExt_3("ext33333333333");
        baseMapper.updateById(pojo);
    }

    public void deleteRow() {
        baseMapper.deleteById(new Integer(1));
    }

    public FinanceLoanPojo selectRow() {
        return baseMapper.selectById(new Integer(1));
    }

    public void insertRows() {
        List<FinanceLoanPojo> rows = new ArrayList<>();
        for (int i=1; i<=2; i++) {
            FinanceLoanPojo pojo = getPojo(i);
            rows.add(pojo);
        }
        baseMapper.insertRows(rows);
    }

    private FinanceLoanPojo getPojo(int index) {
        FinanceLoanPojo pojo = new FinanceLoanPojo();
        pojo.setId(new Integer(index));
        pojo.setFiled_1(100);
        pojo.setFiled_2("f2");
        pojo.setFiled_3("f3");
        pojo.setFiled_4("f4");
        pojo.setFiled_5("f5");
        pojo.setFiled_6("f6");
        pojo.setFiled_7("f7");
        pojo.setFiled_8("f8");
        pojo.setFiled_9("f9");
        pojo.setFiled_10("f10");
        pojo.setFiled_11("f11");
        pojo.setFiled_12(new Timestamp(System.currentTimeMillis()));
        pojo.setFiled_13(new Date(System.currentTimeMillis()));
        pojo.setFiled_14(new Date(System.currentTimeMillis()));
        pojo.setFiled_15(new Date(System.currentTimeMillis()));
        pojo.setFiled_16("f16");
        pojo.setFiled_17(new Integer(index));
        pojo.setFiled_18("f18");
        pojo.setFiled_19(new BigDecimal(index));
        pojo.setFiled_20(new Integer(index));
        pojo.setFiled_21(new Integer(index));
        pojo.setFiled_22(new Integer(index));
        pojo.setFiled_23("f23");
        pojo.setFiled_24("f24");
        pojo.setFiled_25(new BigDecimal(index));
        pojo.setFiled_26(new BigDecimal(index));
        pojo.setFiled_27(new BigDecimal(index));
        pojo.setFiled_28("f28");
        pojo.setFiled_29("f29");
        pojo.setFiled_30("f30");
        pojo.setFiled_31("f31");
        pojo.setFiled_32("f32");
        pojo.setFiled_33("f33");
        pojo.setFiled_34("f34");
        pojo.setFiled_35("f35");
        pojo.setFiled_36(new BigDecimal(index));
        pojo.setFiled_37("f37");
        pojo.setFiled_38("f38");
        pojo.setFiled_39(new Integer(index));
        pojo.setFiled_40(new BigDecimal(index));
        pojo.setFiled_41(new BigDecimal(index));
        pojo.setFiled_42(new BigDecimal(index));
        pojo.setFiled_43(new BigDecimal(index));
        pojo.setRemark("remark");
        pojo.setYn(new Integer(index));
        pojo.setCreate_time(new Timestamp(System.currentTimeMillis()));
        pojo.setUpdate_time(new Timestamp(System.currentTimeMillis()));
        pojo.setExt_1(index + "ext 1");
        pojo.setExt_2(index + "12ext 2");
        pojo.setExt_3(index + "12ext 3");
        return pojo;
    }

}
